/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        ListNode* A=headA,*B=headB;
        while(A!=B)
        {
            A=A!=nullptr?A->next:headB;
            B=B!=nullptr?B->next:headA;
        }
        return A;
    }
};